﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace syc
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>

    public class GetIcon : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string f = context.Request.QueryString["f"];
            if (f == null)
            {
                context.Response.Redirect("/PanelBar/menu_default.gif");
                return;
            }
            f = f.Replace("[", "[[]");
            f = f.Replace("_", "[_]");
            f = f.Replace("%", "[%]");
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.CommandText = "select [图标] from [系统功能] where [图标] IS NOT NULL and [地址] like '%" + f + "'";
            Cmd.CommandType = CommandType.Text;
            object icon = Cmd.ExecuteScalar();
            Cmd.Dispose();
            Conn.Close();
            Conn.Dispose();

            //context.Response.Write(icon.GetType().Name=="DBNull");
            //return;
            if (icon==null)
            {
                context.Response.Redirect("/PanelBar/menu_default.gif");
            }
            else
            {
                context.Response.Redirect((string)icon);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
